<?php

class PopupAnnouncement extends Extension {
	function onAfterInit(){
        if(!$this->owner->redirectedTo()){
        	$announcement = Announcement::get()->filter('IsActive', 1)->filter('PublishDate:LessThanOrEqual', date('Y-m-d'))->filter('ViewGroups.ID', $this->owner->CurrentMember()->RankID)->filter('IsPopup', 1)->first();
			if($announcement && $announcement->IsRead()->filter('IsRead.ID', $this->owner->CurrentMember()->ID)->count() == 0){
				Requirements::javascriptTemplate("announcement/javascript/Announcement.js", array('Title' => $announcement->Title, 'Content' => $announcement->dbObject('Content')->XML()));
				$announcement->IsRead()->add($this->owner->CurrentMember()->ID);
			}
		}
    }
}
